package com.zzedu.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zzedu.common.enums.CommonEnums;
import com.zzedu.common.utils.StringUtils;
import com.zzedu.common.utils.bean.BeanUtils;
import com.zzedu.common.utils.file.FileUtils;
import com.zzedu.common.utils.uuid.IdUtils;
import com.zzedu.domain.ZzPictureNode;
import com.zzedu.domain.ZzSubjectContent;
import com.zzedu.domain.ZzThesaurusWords;
import com.zzedu.domain.ZzUploadFile;
import com.zzedu.dto.ZzSubjectContentDTO;
import com.zzedu.enmuns.*;
import com.zzedu.integration.oss.IOssClientService;
import com.zzedu.integration.oss.dto.FileInfoDTO;
import com.zzedu.integration.oss.dto.OssFileResult;
import com.zzedu.mapper.ZzPictureNodeMapper;
import com.zzedu.mapper.ZzSubjectContentMapper;
import com.zzedu.params.content.VideoParams;
import com.zzedu.params.content.ZzSubjectContentParams;
import com.zzedu.service.IZzSubjectContentService;
import com.zzedu.service.IZzThesaurusWordsService;
import com.zzedu.service.IZzUploadFileService;
import com.zzedu.vo.ContentImageVO;
import com.zzedu.vo.ContentInteractionToFillInTheBlanksVO;
import com.zzedu.vo.ContentVideoVO;
import com.zzedu.vo.SelectOptionVO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 题目内容Service业务层处理
 *
 * @author Mr.Wang
 * @date 2025-04-12
 */
@Service
public class ZzSubjectContentServiceImpl extends ServiceImpl<ZzSubjectContentMapper, ZzSubjectContent> implements IZzSubjectContentService {


    @Autowired
    IZzUploadFileService zzUploadFileService;

    @Autowired
    IOssClientService ossClientService;


    @Autowired
    IZzThesaurusWordsService zzThesaurusWordsService;

    @Autowired
    ZzPictureNodeMapper zzPictureNodeMapper;
    /**
     * 填空
     */
    final String fill_in_the_blanks_key_key = "fill_in_the_blanks";

    @Override
    public LambdaQueryWrapper<ZzSubjectContent> buildQuery(ZzSubjectContentDTO zzSubjectContent) {
        LambdaQueryWrapper<ZzSubjectContent> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(null != zzSubjectContent.getNodeId(), ZzSubjectContent::getNodeId, zzSubjectContent.getNodeId());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(zzSubjectContent.getSubjectType()), ZzSubjectContent::getSubjectType, zzSubjectContent.getSubjectType());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(zzSubjectContent.getInteraction()), ZzSubjectContent::getInteraction, zzSubjectContent.getInteraction());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(zzSubjectContent.getTitle()), ZzSubjectContent::getTitle, zzSubjectContent.getTitle());
        lambdaQueryWrapper.eq(null != zzSubjectContent.getState(), ZzSubjectContent::getState, zzSubjectContent.getState());
        lambdaQueryWrapper.orderByAsc(ZzSubjectContent::getSortNo).orderByDesc(ZzSubjectContent::getId);

        return lambdaQueryWrapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class, readOnly = false)
    public ZzSubjectContent save(ZzSubjectContentParams zzSubjectContentParams) throws Exception {
        ZzSubjectContent zzSubjectContent = new ZzSubjectContent();
        zzSubjectContent.setState(CommonEnums.YES.getCode());
        BeanUtils.copyBeanProp(zzSubjectContent, zzSubjectContentParams);
        LambdaQueryWrapper<ZzSubjectContent> checkSortNoWrapper = Wrappers.lambdaQuery(ZzSubjectContent.class);
        checkSortNoWrapper.eq(ZzSubjectContent::getNodeId, zzSubjectContentParams.getNodeId());
        checkSortNoWrapper.eq(ZzSubjectContent::getSortNo, zzSubjectContentParams.getSortNo());
        if (null != zzSubjectContentParams.getId()) {
            checkSortNoWrapper.ne(ZzSubjectContent::getId, zzSubjectContentParams.getId());
        }
        checkSortNoWrapper.last("limit 1");
        Assert.isTrue(CollectionUtils.isEmpty(this.list(checkSortNoWrapper)), "序号" + zzSubjectContentParams.getSortNo() + "已被占用");
        saveOrUpdate(zzSubjectContent);
        FileRelationTypeEnum fileRelationTypeEnum = FileRelationTypeEnum.SUBJECT_FILE;
        if (QuestionEnum.video.getCode().equals(zzSubjectContentParams.getSubjectType())) {
            VideoParams videoParams = zzSubjectContentParams.getVideoParams();
            ContentVideoVO contentVideoVO = new ContentVideoVO();
            contentVideoVO.setVideoFlag(zzSubjectContentParams.getVideoFlag());
            if (videoParams != null) {
                contentVideoVO.setFileId(videoParams.getId());
                contentVideoVO.setVideoURL(videoParams.getVideoUrl());
                if ("null".equals(contentVideoVO.getVideoURL())) {
                    contentVideoVO.setVideoURL(null);
                }
                if (null != videoParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(videoParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), videoParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        if (null != videoParams.getId()) {
                            uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        }
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentVideoVO.setFileId(uploadFile.getId());
                    }
                }
            }
            videoParams = zzSubjectContentParams.getImageParams();
            if (null != videoParams) {
                contentVideoVO.setImageFileId(videoParams.getId());
                if (null != videoParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(videoParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), videoParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentVideoVO.setImageFileId(uploadFile.getId());
                    }
                }
            }
            zzSubjectContent.setContent(JSON.toJSONString(contentVideoVO));
        } else if (QuestionEnum.image.getCode().equals(zzSubjectContentParams.getSubjectType())) {
            ContentImageVO contentImageVO = new ContentImageVO();
            VideoParams audioParams = zzSubjectContentParams.getAudioParams();
            if (null != audioParams) {
                contentImageVO.setAudioFileId(audioParams.getId());
                if (null != audioParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentImageVO.setAudioFileId(uploadFile.getId());
                    }
                }
            }
            audioParams = zzSubjectContentParams.getImageParams();
            if (null != audioParams) {
                contentImageVO.setImageFileId(audioParams.getId());
                if (null != audioParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentImageVO.setImageFileId(uploadFile.getId());
                    }
                }
            }
            List<VideoParams> musicParams = zzSubjectContentParams.getMusicParams();
            if (CollectionUtils.isNotEmpty(musicParams)) {
                List<Long> musicFileIds = Lists.newArrayList();
                for (VideoParams musicAudio : musicParams) {
                    if (null != musicAudio.getFile()) {
                        OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(musicAudio.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), musicAudio.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                        if (fileUploadResult.isSuccess()) {
                            FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                            ZzUploadFile uploadFile = new ZzUploadFile();
                            uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                            uploadFile.setUrl(fileInfoDTO.getUrl());
                            uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                            uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                            uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                            uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                            uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                            uploadFile.setSize(fileInfoDTO.getSize());
                            uploadFile.setSortNum(uploadFile.getId());
                            zzUploadFileService.save(uploadFile);
                            musicFileIds.add(uploadFile.getId());
                        }
                    } else {
                        musicFileIds.add(musicAudio.getId());
                    }
                }
                contentImageVO.setMusicFileId(musicFileIds);
            }
            zzSubjectContent.setContent(JSON.toJSONString(contentImageVO));
        } else if (QuestionEnum.interaction.getCode().equals(zzSubjectContentParams.getSubjectType())) {
            ContentInteractionToFillInTheBlanksVO contentInteractionVO = new ContentInteractionToFillInTheBlanksVO();
            VideoParams audioParams = zzSubjectContentParams.getAudioParams();
            if (null != audioParams) {
                contentInteractionVO.setAudioFileId(audioParams.getId());
                if (null != audioParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentInteractionVO.setAudioFileId(uploadFile.getId());
                    }
                } else {
                    contentInteractionVO.setAudioFileId(audioParams.getId());
                }
            }
            audioParams = zzSubjectContentParams.getImageParams();
            if (audioParams != null) {
                contentInteractionVO.setImageFileId(audioParams.getId());
                if (null != audioParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentInteractionVO.setImageFileId(uploadFile.getId());
                    }
                } else {
                    contentInteractionVO.setImageFileId(audioParams.getId());
                }
            }
            audioParams = zzSubjectContentParams.getSubjectImage();
            if (audioParams != null) {
                contentInteractionVO.setSubjectImage(audioParams.getId());
                if (null != audioParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentInteractionVO.setSubjectImage(uploadFile.getId());
                    }
                } else {
                    contentInteractionVO.setSubjectImage(audioParams.getId());
                }
            }
            audioParams = zzSubjectContentParams.getSubjectAudio();
            if (audioParams != null) {
                contentInteractionVO.setSubjectAudio(audioParams.getId());
                if (null != audioParams.getFile()) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        contentInteractionVO.setSubjectAudio(uploadFile.getId());
                    }
                } else {
                    contentInteractionVO.setSubjectAudio(audioParams.getId());
                }
            }
            if (null != zzSubjectContentParams.getSelectOptionEnum()) {
                contentInteractionVO.setSelectOptionEnum(zzSubjectContentParams.getSelectOptionEnum().getCode());
            }
            if (CollectionUtils.isNotEmpty(zzSubjectContentParams.getSelectOptionVOList())) {
                List<SelectOptionVO> selectOptionVOList = zzSubjectContentParams.getSelectOptionVOList();
                List<JSONObject> selectList = Lists.newArrayList();
                for (SelectOptionVO selectOptionVO : selectOptionVOList) {
                    JSONObject data = new JSONObject();
                    data.put("id", selectOptionVO.getId());
                    data.put("selectOptionEnum", selectOptionVO.getSelectOptionEnum().getCode());
                    data.put("textContent", selectOptionVO.getTextContent());
                    data.put("isRight", selectOptionVO.getIsRight().getCode());
                    audioParams = selectOptionVO.getFileVideoParams();
                    if (audioParams != null) {
                        if (null != audioParams.getFile()) {
                            OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                            if (fileUploadResult.isSuccess()) {
                                FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                                ZzUploadFile uploadFile = new ZzUploadFile();
                                uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                                uploadFile.setUrl(fileInfoDTO.getUrl());
                                uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                                uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                                uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                                uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                                uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                                uploadFile.setSize(fileInfoDTO.getSize());
                                uploadFile.setSortNum(uploadFile.getId());
                                zzUploadFileService.save(uploadFile);
                                data.put("fileId", uploadFile.getId());
                            }
                        } else {
                            data.put("fileId", audioParams.getId());
                        }
                    }
                    selectList.add(data);
                }
                contentInteractionVO.setSelectOptionVOList(selectList);
            }
            List<VideoParams> markLayerList = zzSubjectContentParams.getMarkLayerList();
            Map<String, String> maskLayer = Maps.newHashMap();
            maskLayer.put("mask_layer_top", zzSubjectContentParams.getMaskLayerTop());
            maskLayer.put("mask_layer_bottom", zzSubjectContentParams.getMaskLayerBottom());
            maskLayer.put("show_model", zzSubjectContentParams.getDefaultMaskLayerShowModel());
            if (CollectionUtils.isNotEmpty(markLayerList)) {
                for (VideoParams videoParams : markLayerList) {
                    if (null != videoParams.getFile()) {
                        OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(videoParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), videoParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                        if (fileUploadResult.isSuccess()) {
                            FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                            ZzUploadFile uploadFile = new ZzUploadFile();
                            uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                            uploadFile.setUrl(fileInfoDTO.getUrl());
                            uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                            uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                            uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                            uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                            uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                            uploadFile.setSize(fileInfoDTO.getSize());
                            zzUploadFileService.save(uploadFile);
                            maskLayer.put(videoParams.getExtraKey(), String.valueOf(uploadFile.getId()));
                        }
                    } else {
                        maskLayer.put(videoParams.getExtraKey(), String.valueOf(videoParams.getId()));
                    }
                }
                contentInteractionVO.setMaskLayer(maskLayer);
            }
            List<Long> dragFileIdList = Lists.newArrayList();
            if (CollectionUtils.isNotEmpty(zzSubjectContentParams.getDragImageList())) {
                for (VideoParams videoParams : zzSubjectContentParams.getDragImageList()) {
                    if (null != videoParams.getFile()) {
                        OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(videoParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), videoParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                        if (fileUploadResult.isSuccess()) {
                            FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                            ZzUploadFile uploadFile = new ZzUploadFile();
                            uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                            uploadFile.setUrl(fileInfoDTO.getUrl());
                            uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                            uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                            uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                            uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                            uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                            uploadFile.setSize(fileInfoDTO.getSize());
                            zzUploadFileService.save(uploadFile);
                            dragFileIdList.add(uploadFile.getId());
                        }
                    } else {
                        dragFileIdList.add(videoParams.getId());
                    }
                }
                contentInteractionVO.setDragFileIdList(dragFileIdList);
            }


            //单词
            List<ZzThesaurusWords> zzThesaurusWordsList = Lists.newArrayList();
            if (CollectionUtils.isNotEmpty(zzSubjectContentParams.getWords())) {
                zzThesaurusWordsList = this.zzThesaurusWordsService.list(Wrappers.lambdaQuery(ZzThesaurusWords.class).in(ZzThesaurusWords::getWord, zzSubjectContentParams.getWords()));
                contentInteractionVO.setWordsId(zzThesaurusWordsList.stream().map(ZzThesaurusWords::getId).collect(Collectors.toList()));
            }
            contentInteractionVO.setWordsList(zzSubjectContentParams.getWords());
            contentInteractionVO.setSentences(Lists.newArrayList());
            InteractionTypeEnums typeEnums = InteractionTypeEnums.getCode(zzSubjectContentParams.getInteraction());
            if (CollectionUtils.isNotEmpty(zzSubjectContentParams.getSentences()) && (
                    InteractionTypeEnums.word_spelling == typeEnums ||
                            InteractionTypeEnums.dub == typeEnums
            )) {
                contentInteractionVO.setSentences(zzSubjectContentParams.getSentences());
                contentInteractionVO.setWordSpellingSentences(zzSubjectContentParams.getWordSpellingSentences());
                audioParams = zzSubjectContentParams.getSentencesAudioParams();
                if (audioParams != null) {
                    contentInteractionVO.setSentencesAudioId(audioParams.getId());
                    if (null != audioParams.getFile()) {
                        OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                        if (fileUploadResult.isSuccess()) {
                            FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                            ZzUploadFile uploadFile = new ZzUploadFile();
                            uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                            uploadFile.setUrl(fileInfoDTO.getUrl());
                            uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                            uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                            uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                            uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                            uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                            uploadFile.setSize(fileInfoDTO.getSize());
                            uploadFile.setSortNum(uploadFile.getId());
                            zzUploadFileService.save(uploadFile);
                            contentInteractionVO.setSentencesAudioId(uploadFile.getId());
                        }
                    } else {
                        contentInteractionVO.setSentencesAudioId(audioParams.getId());
                    }
                }
                audioParams = zzSubjectContentParams.getSentencesImageParams();
                if (audioParams != null) {
                    contentInteractionVO.setSentencesImageId(audioParams.getId());
                    if (null != audioParams.getFile()) {
                        OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(audioParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), audioParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                        if (fileUploadResult.isSuccess()) {
                            FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                            ZzUploadFile uploadFile = new ZzUploadFile();
                            uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                            uploadFile.setUrl(fileInfoDTO.getUrl());
                            uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                            uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                            uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                            uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                            uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                            uploadFile.setSize(fileInfoDTO.getSize());
                            uploadFile.setSortNum(uploadFile.getId());
                            zzUploadFileService.save(uploadFile);
                            contentInteractionVO.setSentencesImageId(uploadFile.getId());
                        }
                    } else {
                        contentInteractionVO.setSentencesImageId(audioParams.getId());
                    }
                }
            }
            if (InteractionTemplateEnums.line_custom == InteractionTemplateEnums.getCode(zzSubjectContentParams.getTemplate())) {
                if (CollectionUtils.isNotEmpty(zzSubjectContentParams.getMain1ImageArray())) {
                    List<Long> fileIdList = Lists.newArrayList();
                    for (VideoParams videoParams : zzSubjectContentParams.getMain1ImageArray()) {
                        if (null != videoParams.getFile()) {
                            OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(videoParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), videoParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                            if (fileUploadResult.isSuccess()) {
                                FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                                ZzUploadFile uploadFile = new ZzUploadFile();
                                uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                                uploadFile.setUrl(fileInfoDTO.getUrl());
                                uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                                uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                                uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                                uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                                uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                                uploadFile.setSize(fileInfoDTO.getSize());
                                zzUploadFileService.save(uploadFile);
                                fileIdList.add(uploadFile.getId());
                            }
                        } else {
                            fileIdList.add(videoParams.getId());
                        }
                    }
                    contentInteractionVO.setFirstMainImageFileIdList(fileIdList);
                }
                if (CollectionUtils.isNotEmpty(zzSubjectContentParams.getMain2ImageArray())) {
                    List<Long> fileIdList = Lists.newArrayList();
                    for (VideoParams videoParams : zzSubjectContentParams.getMain2ImageArray()) {
                        if (null != videoParams.getFile()) {
                            OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(videoParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), videoParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                            if (fileUploadResult.isSuccess()) {
                                FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                                ZzUploadFile uploadFile = new ZzUploadFile();
                                uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                                uploadFile.setUrl(fileInfoDTO.getUrl());
                                uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                                uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                                uploadFile.setRelationId(String.valueOf(zzSubjectContent.getId()));
                                uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                                uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                                uploadFile.setSize(fileInfoDTO.getSize());
                                zzUploadFileService.save(uploadFile);
                                fileIdList.add(uploadFile.getId());
                            }
                        } else {
                            fileIdList.add(videoParams.getId());
                        }
                    }
                    contentInteractionVO.setSecondMainImageFileIdList(fileIdList);
                }
            }
            contentInteractionVO.setWordSpelling(zzSubjectContentParams.getWordSpelling());
            contentInteractionVO.setRightWord(zzSubjectContentParams.getRightWord());
            contentInteractionVO.setSubjectText(zzSubjectContentParams.getSubjectText());
            //选择 #选词填空
            if (fill_in_the_blanks_key_key.equals(zzSubjectContentParams.getInteraction())) {
                if (1 == zzSubjectContentParams.getWordSpelling()) {
                    ZzThesaurusWords rightZzThesaurusWords = zzThesaurusWordsList.stream().filter(word -> zzSubjectContentParams.getRightWord().equals(word.getWord())).findFirst().orElse(null);
                    Assert.notNull(rightZzThesaurusWords, "未设置选词填空正确答案");
                    contentInteractionVO.setRightWordId(rightZzThesaurusWords.getId());
                }
                contentInteractionVO.setRightWord(zzSubjectContentParams.getRightWord());
                contentInteractionVO.setSubjectText(zzSubjectContentParams.getSubjectText());
            }
            zzSubjectContent.setContent(JSON.toJSONString(contentInteractionVO));
        }
        saveOrUpdate(zzSubjectContent);
        return zzSubjectContent;
    }

    @Override
    public Object selectById(Long id) {
        ZzSubjectContent zzSubjectContent = this.getById(id);
        ZzSubjectContentParams zzSubjectContentParams = new ZzSubjectContentParams();
        BeanUtils.copyBeanProp(zzSubjectContentParams, zzSubjectContent);
        zzSubjectContentParams.setMusicParams(Lists.newArrayList());
        zzSubjectContentParams.setAudioParams(new VideoParams());
        zzSubjectContentParams.setImageParams(new VideoParams());
        zzSubjectContentParams.setDragImageList(Lists.newArrayList());
        zzSubjectContentParams.setMarkLayerList(Lists.newArrayList());
        zzSubjectContentParams.setVideoParams(new VideoParams());
        zzSubjectContentParams.setImageParams(new VideoParams());
        zzSubjectContentParams.setSentencesImageParams(new VideoParams());
        zzSubjectContentParams.setSentencesAudioParams(new VideoParams());

        zzSubjectContentParams.setSubjectAudio(new VideoParams());
        zzSubjectContentParams.setSubjectImage(new VideoParams());
        zzSubjectContentParams.setSelectOptionVOList(Lists.newArrayList());

        zzSubjectContentParams.setSentences(Lists.newArrayList());
        zzSubjectContentParams.setWordSpellingSentences(Lists.newArrayList());
        zzSubjectContentParams.setWords(Lists.newArrayList());
        zzSubjectContentParams.setWordSpelling(1);
        if (QuestionEnum.video.getCode().equals(zzSubjectContentParams.getSubjectType())) {
            ContentVideoVO contentVideoVO = JSON.parseObject(zzSubjectContent.getContent(), ContentVideoVO.class);
            VideoParams videoParams = new VideoParams();
            videoParams.setVideoUrl(contentVideoVO.getVideoURL());
            videoParams.setId(contentVideoVO.getFileId());
            if (null != contentVideoVO.getFileId()) {
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentVideoVO.getFileId());
                videoParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                videoParams.setName(zzUploadFile.getFileName());
            }
            VideoParams imageParams = new VideoParams();
            if (null != contentVideoVO.getImageFileId()) {
                imageParams.setId(contentVideoVO.getImageFileId());
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentVideoVO.getImageFileId());
                imageParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                imageParams.setName(zzUploadFile.getFileName());
            }
            zzSubjectContentParams.setVideoFlag(contentVideoVO.getVideoFlag());
            zzSubjectContentParams.setVideoParams(videoParams);
            zzSubjectContentParams.setImageParams(imageParams);
        } else if (QuestionEnum.image.getCode().equals(zzSubjectContentParams.getSubjectType())) {
            ContentImageVO contentImageVO = JSON.parseObject(zzSubjectContent.getContent(), ContentImageVO.class);
            VideoParams videoParams = new VideoParams();
            videoParams.setId(contentImageVO.getAudioFileId());
            if (null != contentImageVO.getAudioFileId()) {
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentImageVO.getAudioFileId());
                videoParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                videoParams.setName(zzUploadFile.getFileName());
            }
            zzSubjectContentParams.setAudioParams(videoParams);

            VideoParams imageParams = new VideoParams();
            imageParams.setId(contentImageVO.getImageFileId());
            if (null != contentImageVO.getImageFileId()) {
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentImageVO.getImageFileId());
                imageParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                imageParams.setName(zzUploadFile.getFileName());
            }
            zzSubjectContentParams.setImageParams(imageParams);
            if (CollectionUtils.isNotEmpty(contentImageVO.getMusicFileId())) {
                for (Long fId : contentImageVO.getMusicFileId()) {
                    VideoParams musicParams = new VideoParams();
                    musicParams.setId(fId);
                    if (null != musicParams.getId()) {
                        ZzUploadFile zzUploadFile = zzUploadFileService.getById(musicParams.getId());
                        musicParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                        musicParams.setName(zzUploadFile.getFileName());
                        zzSubjectContentParams.getMusicParams().add(musicParams);
                    }
                }
            }

        } else {
            ContentInteractionToFillInTheBlanksVO contentInteractionVO = JSON.parseObject(zzSubjectContent.getContent(), ContentInteractionToFillInTheBlanksVO.class);
            zzSubjectContentParams.setSelectOptionEnum(SelectOptionEnum.getCode(contentInteractionVO.getSelectOptionEnum()));
            zzSubjectContentParams.setRightWord(contentInteractionVO.getRightWord());
            zzSubjectContentParams.setSubjectText(contentInteractionVO.getSubjectText());
            Long rightWordId = null;
            if (fill_in_the_blanks_key_key.equals(zzSubjectContentParams.getInteraction())) {
                ContentInteractionToFillInTheBlanksVO contentInteractionToFillInTheBlanksVO = (ContentInteractionToFillInTheBlanksVO) contentInteractionVO;
                zzSubjectContentParams.setSubjectText(contentInteractionToFillInTheBlanksVO.getSubjectText());
                rightWordId = contentInteractionToFillInTheBlanksVO.getRightWordId();
                zzSubjectContentParams.setRightWord(contentInteractionToFillInTheBlanksVO.getRightWord());
            }
            zzSubjectContentParams.setWordSpelling(contentInteractionVO.getWordSpelling());
            InteractionTypeEnums typeEnums = InteractionTypeEnums.getCode(zzSubjectContentParams.getInteraction());
            if (CollectionUtils.isNotEmpty(contentInteractionVO.getSentences()) && (
                    InteractionTypeEnums.word_spelling == typeEnums ||
                            InteractionTypeEnums.dub == typeEnums
            )) {
                if (CollectionUtils.isNotEmpty(contentInteractionVO.getSentences())) {
                    zzSubjectContentParams.setSentences(contentInteractionVO.getSentences());
                    zzSubjectContentParams.setWordSpellingSentences(contentInteractionVO.getWordSpellingSentences());
                }
                if (null != contentInteractionVO.getSentencesAudioId()) {
                    VideoParams sentencesAudioParams = new VideoParams();
                    ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentInteractionVO.getSentencesAudioId());
                    sentencesAudioParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                    sentencesAudioParams.setName(zzUploadFile.getFileName());
                    sentencesAudioParams.setId(contentInteractionVO.getSentencesAudioId());
                    zzSubjectContentParams.setSentencesAudioParams(sentencesAudioParams);
                }
                if (null != contentInteractionVO.getSentencesImageId()) {
                    VideoParams sentencesAudioParams = new VideoParams();
                    ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentInteractionVO.getSentencesImageId());
                    sentencesAudioParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                    sentencesAudioParams.setName(zzUploadFile.getFileName());
                    sentencesAudioParams.setId(contentInteractionVO.getSentencesImageId());
                    zzSubjectContentParams.setSentencesImageParams(sentencesAudioParams);
                }
            }
            VideoParams videoParams = new VideoParams();
            if (null != contentInteractionVO.getAudioFileId()) {
                videoParams.setId(contentInteractionVO.getAudioFileId());
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentInteractionVO.getAudioFileId());
                videoParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                videoParams.setName(zzUploadFile.getFileName());
            }
            zzSubjectContentParams.setAudioParams(videoParams);
            VideoParams imageParams = new VideoParams();
            if (null != contentInteractionVO.getImageFileId()) {
                imageParams.setId(contentInteractionVO.getImageFileId());
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentInteractionVO.getImageFileId());
                imageParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                imageParams.setName(zzUploadFile.getFileName());
            }
            zzSubjectContentParams.setImageParams(imageParams);
            Map<String, String> maskLayer = contentInteractionVO.getMaskLayer();
            if (null != contentInteractionVO.getWordSpelling() && 2 == contentInteractionVO.getWordSpelling()) {
                if (CollectionUtils.isNotEmpty(contentInteractionVO.getWordsList())) {
                    zzSubjectContentParams.setWords(contentInteractionVO.getWordsList());
                }
            } else {
                if (CollectionUtils.isNotEmpty(contentInteractionVO.getWordsId())) {
                    //单词
                    List<ZzThesaurusWords> zzThesaurusWordsList = this.zzThesaurusWordsService.list(Wrappers.lambdaQuery(ZzThesaurusWords.class)
                            .in(ZzThesaurusWords::getId, contentInteractionVO.getWordsId()));
                    if (null != contentInteractionVO.getRightWordId()) {
                        ZzThesaurusWords rightZzThesaurusWords = zzThesaurusWordsList.stream().filter(word -> word.getId().equals(contentInteractionVO.getRightWordId())).findFirst().orElse(null);
                        if (null != rightZzThesaurusWords) {
                            zzSubjectContentParams.setRightWord(rightZzThesaurusWords.getWord());
                        }
                    }
                    zzSubjectContentParams.setWords(zzThesaurusWordsList.stream().map(ZzThesaurusWords::getWord).collect(Collectors.toList()));
                }
            }
            if (MapUtils.isNotEmpty(maskLayer)) {
                //背景图
                Long imageId = contentInteractionVO.getImageFileId();
                if (null != imageId) {
                    imageParams = new VideoParams();
                    imageParams.setId(imageId);
                    ZzUploadFile zzUploadFile = zzUploadFileService.getById(imageId);
                    imageParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                    imageParams.setName(zzUploadFile.getFileName());
                }
                zzSubjectContentParams.setMaskLayerTop(MapUtils.getString(maskLayer, "mask_layer_top", null));
                zzSubjectContentParams.setMaskLayerBottom(MapUtils.getString(maskLayer, "mask_layer_bottom", null));
                zzSubjectContentParams.setDefaultMaskLayerShowModel(MapUtils.getString(maskLayer, "show_model", null));
                maskLayer.remove("mask_layer_top");
                maskLayer.remove("mask_layer_bottom");
                maskLayer.remove("show_model");
                zzSubjectContentParams.setImageParams(imageParams);
                List<VideoParams> markLayerList = Lists.newArrayList();
                for (String key : maskLayer.keySet()) {
                    if (MapUtils.getLong(maskLayer, key, null) != null) {
                        VideoParams files = new VideoParams();
                        ZzUploadFile zzUploadFile = zzUploadFileService.getById(MapUtils.getLong(maskLayer, key));
                        files.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                        files.setId(MapUtils.getLong(maskLayer, key));
                        files.setExtraKey(key);
                        files.setName(zzUploadFile.getFileName());
                        markLayerList.add(files);
                    }
                }
                zzSubjectContentParams.setMarkLayerList(markLayerList);
            }
            zzSubjectContentParams.setDragImageList(Lists.newArrayList());
            if (CollectionUtils.isNotEmpty(contentInteractionVO.getDragFileIdList())) {
                for (Long dragFileId : contentInteractionVO.getDragFileIdList()) {
                    VideoParams files = new VideoParams();
                    ZzUploadFile zzUploadFile = zzUploadFileService.getById(dragFileId);
                    files.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                    files.setId(dragFileId);
                    files.setName(zzUploadFile.getFileName());
                    zzSubjectContentParams.getDragImageList().add(files);
                }
            }
            zzSubjectContentParams.setMain1ImageArray(Lists.newArrayList());
            zzSubjectContentParams.setMain2ImageArray(Lists.newArrayList());

            if (InteractionTemplateEnums.line_custom == InteractionTemplateEnums.getCode(zzSubjectContentParams.getTemplate())) {
                if (CollectionUtils.isNotEmpty(contentInteractionVO.getFirstMainImageFileIdList())) {
                    for (Long fileId : contentInteractionVO.getFirstMainImageFileIdList()) {
                        VideoParams files = new VideoParams();
                        ZzUploadFile zzUploadFile = zzUploadFileService.getById(fileId);
                        files.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                        files.setId(fileId);
                        files.setName(zzUploadFile.getFileName());
                        zzSubjectContentParams.getMain1ImageArray().add(files);
                    }
                }
                if (CollectionUtils.isNotEmpty(contentInteractionVO.getSecondMainImageFileIdList())) {
                    for (Long fileId : contentInteractionVO.getSecondMainImageFileIdList()) {
                        VideoParams files = new VideoParams();
                        ZzUploadFile zzUploadFile = zzUploadFileService.getById(fileId);
                        files.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                        files.setId(fileId);
                        files.setName(zzUploadFile.getFileName());
                        zzSubjectContentParams.getMain2ImageArray().add(files);
                    }
                }
            }
            if (null != contentInteractionVO.getSubjectAudio()) {
                VideoParams subjectAudio = new VideoParams();
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentInteractionVO.getSubjectAudio());
                subjectAudio.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                subjectAudio.setName(zzUploadFile.getFileName());
                subjectAudio.setId(contentInteractionVO.getSubjectAudio());
                zzSubjectContentParams.setSubjectAudio(subjectAudio);
            }
            if (null != contentInteractionVO.getSubjectImage()) {
                VideoParams subjectImage = new VideoParams();
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(contentInteractionVO.getSubjectImage());
                subjectImage.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                subjectImage.setName(zzUploadFile.getFileName());
                subjectImage.setId(contentInteractionVO.getSubjectImage());
                zzSubjectContentParams.setSubjectImage(subjectImage);
            }
            if (CollectionUtils.isNotEmpty(contentInteractionVO.getSelectOptionVOList())) {
                if (SelectOptionEnum.text == zzSubjectContentParams.getSelectOptionEnum()) {
                    for (JSONObject jsonObject : contentInteractionVO.getSelectOptionVOList()) {
                        SelectOptionVO selectOptionVO = new SelectOptionVO();
                        selectOptionVO.setSelectOptionEnum(zzSubjectContentParams.getSelectOptionEnum());
                        selectOptionVO.setIsRight(CommonEnums.getCode(MapUtils.getInteger(jsonObject, "isRight")));
                        selectOptionVO.setTextContent(MapUtils.getString(jsonObject, "textContent"));
                        zzSubjectContentParams.getSelectOptionVOList().add(selectOptionVO);
                    }
                } else {
                    for (JSONObject jsonObject : contentInteractionVO.getSelectOptionVOList()) {
                        SelectOptionVO selectOptionVO = new SelectOptionVO();
                        selectOptionVO.setSelectOptionEnum(zzSubjectContentParams.getSelectOptionEnum());
                        selectOptionVO.setIsRight(CommonEnums.getCode(MapUtils.getInteger(jsonObject, "isRight")));
                        Long fileId = MapUtils.getLong(jsonObject, "fileId");

                        ZzUploadFile zzUploadFile = zzUploadFileService.getById(fileId);
                        VideoParams fileVideoParams = new VideoParams();
                        fileVideoParams.setHttpFileUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                        fileVideoParams.setName(zzUploadFile.getFileName());
                        fileVideoParams.setId(fileId);
                        selectOptionVO.setFileVideoParams(fileVideoParams);
                        zzSubjectContentParams.getSelectOptionVOList().add(selectOptionVO);
                    }
                }
            }
        }
        return zzSubjectContentParams;
    }

    @Override
    public IPage<Map<String, Object>> getSubmitDataByDate(IPage page, LocalDateTime start, LocalDateTime end) {
        return baseMapper.getSubmitDataByDate(page, start, end);
    }

    @Override
    public long getCountByBookId(Long id) {
        Long count = 0L;
        //绘本下所有节点
        List<ZzPictureNode> zzPictureNodeList = this.zzPictureNodeMapper.selectList(Wrappers.lambdaQuery(ZzPictureNode.class)
                .eq(ZzPictureNode::getPictureBookId, id)
                .eq(ZzPictureNode::getNodeType, 3)
        );
        if (CollectionUtils.isNotEmpty(zzPictureNodeList)) {
            List<Long> nodeIdList = Lists.newArrayList();
            nodeIdList.addAll(zzPictureNodeList.stream().map(ZzPictureNode::getId).collect(Collectors.toList()));
            List<ZzPictureNode> childZzPictureNodeList = this.zzPictureNodeMapper.selectList(Wrappers.lambdaQuery(ZzPictureNode.class)
                    .in(ZzPictureNode::getpNodeId, nodeIdList)
                    .eq(ZzPictureNode::getNodeType, 2));
            if (CollectionUtils.isNotEmpty(childZzPictureNodeList)) {
                nodeIdList.addAll(childZzPictureNodeList.stream().map(ZzPictureNode::getId).collect(Collectors.toList()));
            }
            //子节点
            LambdaQueryWrapper<ZzSubjectContent> lambdaQueryWrapper = Wrappers.lambdaQuery(ZzSubjectContent.class);
            lambdaQueryWrapper.select(ZzSubjectContent::getId);
            lambdaQueryWrapper.eq(ZzSubjectContent::getState, CommonEnums.YES.getCode());
            lambdaQueryWrapper.in(ZzSubjectContent::getNodeId, nodeIdList);
            count = this.count(lambdaQueryWrapper);
        }
        return count;
    }
}